// JavaScript Document
var photoType = Array('靓丽美眉','可爱卡通','人偶迷情','帅气男孩','唯美浪漫');
var photoTypeEncode = Array('llmm','kakt','romq','sqnh','wmlm');
var photoNum = Array('15','20','20','15','20');

//获取默认头像地址
function getHeadImage()
{
	var str = "";
	var imgName = "";
	var folderPath = "http://192.168.1.38/pomohox/images/headimg/";
	for ( var i = 0; i < photoType.length; i ++ )
	{
		if ( i == 0 )
		{
			str += "<dt class=\"s"+ (i+1) +" ac\"><a href=\"javascript:;\">"+ photoType[i] +"</a></dt>";
			str += "<dd>";
		}
		else
		{
			str += "<dt class=\"s"+ (i+1) +"\"><a href=\"javascript:;\">"+ photoType[i] +"</a></dt>";
			str += "<dd class=\"none\">";
		}
		for ( var j = 0; j < photoNum[i]; j ++ )
		{
			if ( j < 9 )
			{
				imgName = "0" + (j + 1);
				
			}
			else
			{
				imgName = j + 1;
			}
			str += "<div class='l'>";
			str += "<a href=\"javascript:;\" title='"+ photoType[i] + imgName +"' onclick=\"chooseSystemHead('sys"+ photoTypeEncode[i] + imgName +"');\"><img id='sys"+ photoTypeEncode[i] + imgName +"' alt='"+ photoType[i] + imgName +"' src='"+ folderPath + photoTypeEncode[i] + "/" + imgName +".jpg'></a><br />";
			str += "</div>";
		}
		str += "</dd>";
	}
	document.write( str );
}

//重设头像
function resetImgHead()
{
	document.getElementById("hidImgHeadType").value = 0;//设置头像类型
	//document.getElementById("imgHead").src = document.getElementById("hidImgHead").value
	document.getElementById("showImgHead").src = document.getElementById("hidImgHead").value
}

//上传头像预览
function previewImg()
{
	var objFile = document.getElementById("fileImgHead");
	var sFilePath = objFile.value;
	sFilePath = sFilePath.replace(/\\/g,"/");
	if ( sFilePath != "" && sFilePath != null && sFilePath.length>4 )
	{
		sFilePath = "file:///" + sFilePath;
		var sFileExt = sFilePath.substr(sFilePath.lastIndexOf('.'),(sFilePath.length-sFilePath.lastIndexOf('.')));
		sFileExt = sFileExt.toUpperCase();		
		if ( sFileExt!=".GIF" && sFileExt!=".JPG" && sFileExt!=".JPEG" && sFileExt!=".PNG")
		{
			alert( "无效图片: 请选择 GIF,JPG,JPEG,PNG 文件。" );
			document.getElementById("divFile").innerHTML = "<input name=\"fileImgHead\" id=\"fileImgHead\" type=\"file\" size=\"20\" onChange=\"previewImg()\" />";
		}
		else
		{	
			//设置头像类型
			document.getElementById("hidImgHeadType").value = 1;
			if(document.all)
			{
				//document.getElementById("imgHead").src = sFilePath;
				//document.getElementById("headImg").src = sFilePath;
				document.getElementById("showImgHead").src = sFilePath;
			}
			else
			{
				document.getElementById("divImgCheckInfo").style.display = "block";
				document.getElementById("divImgCheckInfo").innerHTML = "<span class=\"sign_right\">图片有效，爆上去后将设为头像</span>";				
			}
		}
		//设置图片大小，宽，高
		setImgSize();
	}
	else
	{
		if ( sFilePath != "" && sFilePath != null )
		{
			alert( "无效图片: 请选择 GIF 或 JPG 文件。" );
			document.getElementById("divFile").innerHTML = "<input name=\"fileImgHead\" id=\"fileImgHead\" type=\"file\" size=\"20\" onChange=\"previewImg()\" />";
		}
	}
}


function previewImgHeadFromFlash( sPhotoUrl )
{
	//document.getElementById("imgHead").src = sPhotoUrl;
	document.getElementById("showImgHead").src = sPhotoUrl;
}

//选择默认头像
function chooseSystemHead(obj)
{
	var systemHeadPath = document.getElementById(obj).src;
	//设置头像类型
	document.getElementById("hidImgHeadType").value = 3;
	if(document.all)
	{
		//document.getElementById("imgHead").src = systemHeadPath;
		document.getElementById("showImgHead").src = systemHeadPath;
	}
	else
	{
		var str = "<span>头像预览</span><br>";
		//str += "<img id=\"imgHead\" name=\"imgHead\" runat=\"server\" src=\""+ systemHeadPath +"\">";
		str += "<img id=\"showImgHead\" name=\"showImgHead\" runat=\"server\" src=\""+ systemHeadPath +"\">";
		document.getElementById("showPhoto").innerHTML = str;
	}
	document.getElementById("hidSysImgHead").value = systemHeadPath;
	//window.setTimeout( "document.getElementById('oldPhoto').focus();", 50);
	//document.getElementById("fileImgHead").focus();

}

//获取图片大小，宽，高
function setImgSize()
{
	/*document.getElementById("hidImgHeadSize").value = document.getElementById("imgHead").fileSize;
	document.getElementById("hidImgHeadWidth").value = document.getElementById("imgHead").width;
	document.getElementById("hidImgHeadHeight").value = document.getElementById("imgHead").height;	*/
	document.getElementById("hidImgHeadSize").value = document.getElementById("showImgHead").fileSize;
	document.getElementById("hidImgHeadWidth").value = document.getElementById("showImgHead").width;
	document.getElementById("hidImgHeadHeight").value = document.getElementById("showImgHead").height;	
}

//处理Flash
//function showFlashPhoto( iPhotoID, sPhotoUrl )
//{
//	if ( iPhotoID>0 && sPhotoUrl!="" )
//	{
//		//清除上传文件
//		document.getElementById("divFile").innerHTML = "<input name=\"fileImgHead\" id=\"fileImgHead\" type=\"file\" size=\"20\" onChange=\"previewImg()\" />";
//		//设置头像类型
//		document.getElementById("hidImgHeadType").value = 2;
//		document.getElementById("divImgCheckInfo").style.display = "none";
//
//		document.getElementById("hidPhotoID").value = iPhotoID;
//		document.getElementById("hidImgHeadFlash").value = sPhotoUrl;
//		setTimeout( "previewImgHeadFromFlash('" + sPhotoUrl +"')", 2*1000 );
//	}
//}

function previewImgHeadFromFlash( sPhotoUrl )
{
	document.getElementById("imgHead").src = sPhotoUrl;
}
//选择头像类型
function headM(){
	$(".nav_box a").each(function(i){
		$(this).click(function(){
			$(".nav_box a").removeClass("ac");
			$(".photo_box").css("display","none");
			$(this).addClass("ac");
			$(".photo_box:eq("+i+")").css("display","");
			});
		});
	}

	